package com.neu.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.neu.dao.StudentDao;
import com.neu.entity.Student;
import com.neu.util.JDBCUtil;

public class StudentDaoImpl implements StudentDao {
/**
 * 登录
 */
	@Override
	public boolean denglu(Student st) throws SQLException {
		Connection conn= null;
		try {
			conn=JDBCUtil.getConn();
		} catch (ClassNotFoundException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String sql = "select * from tb_users_role where name=? and pass=?";
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setString(1, st.getName());
		ps.setString(2, st.getPass());
		ResultSet rt = ps.executeQuery();
		while(rt.next()) {
			System.out.println("登录成功："+st.getName()+","+st.getPass());
		}
		return true;
	}
/**
 * 注册
 */
	@Override
	public boolean zhuce(Student st) throws SQLException {
		Connection conn = null;
		try {
			conn = JDBCUtil.getConn();
		} catch (ClassNotFoundException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String sql = "insert into tb_users_role value(null,?,?,0)";
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setString(1, st.getName());
		ps.setString(2, st.getPass());
		int a = ps.executeUpdate();
		if(a>0) {
			System.out.println("注册成功："+st.getName()+","+st.getPass());
		}
		return true;
	}

}
